﻿using UnityEngine;
using UnityEngine.Events;

/// <summary>
/// 复用列表
/// </summary>
public interface IUIReuseList
{
    /// <summary>
    /// 数量
    /// </summary>
    int Count { get; }
    /// <summary>
    /// 刷新
    /// </summary>
    /// <param name="count"></param>
    /// <param name="userData"></param>
    void Refresh(int count, object userData = null, int selectIndex = -1);
    /// <summary>
    /// 刷新所有（已调用过Refresh后执行此函数有效）
    /// </summary>
    void RefreshAll();
    /// <summary>
    /// 视口
    /// </summary>
    RectTransform Viewport { get; }
    /// <summary>
    /// Content
    /// </summary>
    RectTransform Content { get; }
    /// <summary>
    /// gameObject(UIReuseList所在的go)
    /// </summary>
    GameObject gameObject { get; }
    /// <summary>
    /// 内容大小(x: width, y: height)
    /// </summary>
    Vector2 ContentSize { get; }
    /// <summary>
    /// 获取Item位置 (Viewport笛卡尔坐标系)
    /// </summary>
    /// <param name="index">下标</param>
    /// <returns></returns>
    Vector2 GetAnchoredPosition(int index);
    /// <summary>
    /// 获取Item世界坐标
    /// </summary>
    /// <param name="index">下标</param>
    /// <returns></returns>
    Vector3 GetPosition(int index);
    /// <summary>
    /// 获取Item本地坐标位置
    /// </summary>
    /// <param name="index">下标</param>
    /// <returns></returns>
    Vector2 GetLocalPosition(int index);
    /// <summary>
    /// 选中
    /// </summary>
    /// <param name="index">下标</param>
    void Select(int index);
    /// <summary>
    /// 是否选中
    /// </summary>
    /// <param name="index"></param>
    /// <returns></returns>
    bool IsSelected(int index);
    /// <summary>
    /// Item选中回调 (Item预制需勾选Selectable)
    ///     * last: 上一个选中的下标 (未选中时是-1)
    ///     * current: 当前选中的下标
    /// </summary>
    ReuseItemSelected OnSelected { get; }
}

public class ReuseItemSelected : UnityEvent<int, int> { }
